/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package east2west.action;

import east2west.dto.JobDTO;
import east2west.dto.SaleTourDTO;
import east2west.dto.SeasonsDTO;
import east2west.dto.TourTypeDTO;
import east2west.service.JobService;
import east2west.service.SeasonService;
import east2west.service.TourService;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

/**
 *
 * @author nguyendat
 */
public class SaleTourAction extends DispatchAction {

    TourService tourSer = new TourService();
    JobService jobser = new JobService();
    SeasonService seasonser = new SeasonService();
    private final static String SUCCESS = "success";

    public ActionForward TotalT(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int typeId = Integer.parseInt(request.getParameter("type"));
        float sumTypeName = tourSer.saleTourType(typeId);
        request.setAttribute("sumTypeName", sumTypeName);
        ArrayList<SaleTourDTO> listFill = tourSer.listFillter();
        request.setAttribute("listFill", listFill);

        ArrayList<TourTypeDTO> listTourType = tourSer.readByTourType();
        request.setAttribute("listTourType", listTourType);
        request.setAttribute("page", "saletourtype.page");
        return mapping.findForward(SUCCESS);
    }

    public ActionForward saleList(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ArrayList<TourTypeDTO> listTourType = tourSer.readByTourType();
        request.setAttribute("listTourType", listTourType);
        request.setAttribute("page", "saletour.page");
        return mapping.findForward(SUCCESS);
    }

    public ActionForward listAll(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        ArrayList<SaleTourDTO> listSale = tourSer.listAllSaleTour();
        request.setAttribute("listSale", listSale);

        request.setAttribute("page", "saletour.page");
        return mapping.findForward(SUCCESS);
    }

    public ActionForward listFillter(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        ArrayList<SaleTourDTO> listFill = tourSer.listFillter();
        request.setAttribute("listFill", listFill);

        request.setAttribute("page", "saletourduration.page");
        return mapping.findForward(SUCCESS);

    }

    public ActionForward listFillterT(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        ArrayList<SaleTourDTO> listFill = tourSer.listFillter();
        request.setAttribute("listFill", listFill);

        ArrayList<TourTypeDTO> listTourType = tourSer.readByTourType();
        request.setAttribute("listTourType", listTourType);

        request.setAttribute("page", "saletourtype.page");
        return mapping.findForward(SUCCESS);

    }

    public ActionForward listFillterP(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        ArrayList<SaleTourDTO> listFill = tourSer.listFillter();
        request.setAttribute("listFill", listFill);


        request.setAttribute("page", "saletourcost.page");
        return mapping.findForward(SUCCESS);

    }

    public ActionForward listFillterJ(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        ArrayList<SaleTourDTO> listFill = tourSer.listFillter();
        request.setAttribute("listFill", listFill);

        ArrayList<JobDTO> listJob = jobser.readByAll();
        request.setAttribute("listJob", listJob);
        request.setAttribute("page", "saletourgroup.page");
        return mapping.findForward(SUCCESS);

    }
 public ActionForward listFillterS(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        ArrayList<SaleTourDTO> listFill = tourSer.listFillter();
        request.setAttribute("listFill", listFill);

        ArrayList<SeasonsDTO> listSeasonName = seasonser.findBySeasonName();
        request.setAttribute("listSeason", listSeasonName);

        request.setAttribute("page", "saletourseason.page");
        return mapping.findForward(SUCCESS);

    }
    public ActionForward TotalD(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        int duration = Integer.parseInt(request.getParameter("duration"));

        float sum = tourSer.totalDuration(duration);
        ArrayList<SaleTourDTO> listFill = tourSer.listFillter();
        request.setAttribute("listFill", listFill);
        request.setAttribute("sum", sum);
        request.setAttribute("duration", duration);
        request.setAttribute("page", "saletourduration.page");

        return mapping.findForward(SUCCESS);

    }

    public ActionForward TotalP(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        float price1 = Integer.parseInt(request.getParameter("price1"));
        float price2 = Integer.parseInt(request.getParameter("price2"));
        float sum = tourSer.totalCost(price1, price2);
        ArrayList<SaleTourDTO> listFill = tourSer.listFillter();
        request.setAttribute("listFill", listFill);
        request.setAttribute("sum", sum);
        request.setAttribute("price1", price1);
        request.setAttribute("price2", price2);
        request.setAttribute("page", "saletourcost.page");

        return mapping.findForward(SUCCESS);

    }

    public ActionForward TotalJ(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int job = Integer.parseInt(request.getParameter("job"));
        float sum = tourSer.saleTourType(job);
        request.setAttribute("sum", sum);
        ArrayList<SaleTourDTO> listFill = tourSer.listFillter();
        request.setAttribute("listFill", listFill);

        ArrayList<JobDTO> listJob = jobser.readByAll();
        request.setAttribute("listJob", listJob);
        request.setAttribute("page", "saletourgroup.page");
        return mapping.findForward(SUCCESS);
    }
     public ActionForward TotalS(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {

         int season = Integer.parseInt(request.getParameter("season"));
         SeasonsDTO seasonDTO = seasonser.readByIdMonth(season);
        float sum = tourSer.totalSeason(seasonDTO.getStart(), seasonDTO.getEnd());
        ArrayList<SaleTourDTO> listFill = tourSer.listFillter();
        request.setAttribute("listFill", listFill);

          ArrayList<SeasonsDTO> listSeasonName = seasonser.findBySeasonName();
        request.setAttribute("listSeason", listSeasonName);
        request.setAttribute("sum", sum);
        request.setAttribute("month1", seasonDTO.getStart());
        request.setAttribute("month2",  seasonDTO.getEnd());
        request.setAttribute("page","saletourseason.page");

        return mapping.findForward(SUCCESS);

    }

}
